<template>
	<view>
		<view class="" style="padding-bottom: 20upx;">
			<view v-for="(item) in list" :key="item.id" class="center">
				<view class="grid" @tap="godetail(item.id)" style="">
					<view class="">
						<image class="grid-image" :src="item.cover_img" mode="scaleToFill"></image>
						<view class="text">{{item.name}}</view>
					</view>
					<!-- <view class="grid-text">
						{{item.product_introduct}}
					</view>
					<view class="d-flex">
						<view class="flex-1 price">￥{{item.member_price}} </view>
						<view class="sale sale1">已售{{item.sell_num}}</view>
						<view class="six  sale1"></view>
					</view> -->
				</view>
			</view>
			<view class="" style="text-align: center;width: 100%;">
				<uni-load-more :status="loadingType"></uni-load-more>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page: 1,
				loadingType: 'more', //加载更多状态
				totalCount: 0,
				list: []
			}
		},

		//下拉刷新
		onPullDownRefresh() {
			this.getLists('refresh')
		},
		//加载更多
		onReachBottom() {
			this.getLists()
		},

		onLoad() {
			this.getLists()
		},

		methods: {
			async getLists(type = 'add') {
				if (type === 'add') {
					if (this.loadingType === 'nomore') {
						return;
					}
					this.loadingType = 'loading';
				} else {
					this.page = 1;
					this.loadingType = 'more'
				}
				let dataObj = {
					page: this.page,
				}
				let ret = await this.$myRequest({
					url: "/stamps_lists",
					data: dataObj
				})

				let ndata = ret.data.data.list;
				let count = ret.data.data.totalCount;
				this.totalCount = count;

				if (this.page === 1) {
					this.list = ndata;
					if (ndata.length === 0) {
						this.loadingType = 'nomore'
					} else {
						this.page = this.page + 1;
					}
				} else {
					if (ndata.length === 0) {
						this.loadingType = 'nomore'
					} else {
						this.list = [...this.list, ...ndata];
						if (this.list.length < this.totalCount) {
							this.page = this.page + 1;
						}
					}
				}

				//判断是否还有下一页，有是more  没有是nomore(测试数据判断大于20就没有了)
				this.loadingType = this.list.length < this.totalCount ? 'more' : 'nomore';

				if (type === 'refresh') {
					setTimeout(function() {
						uni.stopPullDownRefresh();
					}, 500)
				}
			},

			async godetail(id) {
				uni.navigateTo({
					url: '/pages/stamps/detail?id=' + id
				})
			},
			
		},
	}
</script>

<style lang="scss">
	.center {
		display: inline-flex;
		margin-top: 20rpx;
		margin-left: 15rpx;
	}

	.grid {
		background-color: white;
		width: 350rpx;
		height: 100%;
		border-radius: 20rpx;
	}

	.grid-image {
		width: 100%;
		height: 360rpx;
		// margin: 70rpx 0 30rpx 100rpx;
	}

	.text {
		display: -webkit-box;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
		letter-spacing: 2rpx;
		word-break: normal;
		overflow: hidden;
		text-overflow: ellipsis;
		margin-bottom: 8rpx;
		margin-left: 15rpx;
		font-size: 28rpx;
	}

	.grid-text {
		color: #999;
		font-size: 24rpx;
		letter-spacing: 3rpx;
		margin: 10rpx 0 20rpx 15rpx;
	}

	.price {
		color: #e80909;
		margin-left: 15rpx;
		margin-bottom: 10rpx;
	}

	.sale1 {
		font-size: 26rpx;
		letter-spacing: 3rpx;
		color: #999;
		margin-top: 5rpx;
	}

	.six {
		margin-left: 10rpx;
		margin-right: 25rpx;
	}

	page {
		background-color: #f5f5f5;
	}

	scroll-view ::-webkit-scrollbar {
		display: none;
	}

	.scroll {
		width: 100%;
		white-space: nowrap;
		border-bottom: 1px solid #fff;

		.tab-scroll_item {
			white-space: normal;
			display: inline-block;
			margin: 0 20rpx;
			padding: 10rpx 0;
		}

		& view:before {
			color: #f4f4f4;
			margin: 0 30rpx;
		}

		& view:first-child:before {
			display: none;
		}

	}

	.select {
		color: #e80909;
		border-bottom: 4rpx solid #e80909;
	}

	.list-item {
		overflow: hidden;
		height: 100%;
		width: 100%;

		.list {
			// float: left;
			width: 50%;
			height: 100%;
			margin: 20rpx 0 0 3%;
			border: 1rpx solid #eaeaea;
			background-color: #ffffff;
			border-radius: 12rpx;
		}
	}

	.header {
		background-color: white;
	}

	.search-input {
		background-color: #f8f8f8;
		width: 700rpx;
		height: 70rpx;
		margin: 100rpx 32rpx 20rpx 32rpx;
		border-radius: 10rpx;

		image {
			display: flex;
			margin: 20rpx 30rpx 0 20rpx;
		}

		view {
			font-size: 28rpx;
			color: #545556;
			margin-top: -35rpx;
			margin-left: 60rpx;

		}
	}
</style>